<template>
	<view class="transform">
		<view class="business">
			<view class="inputlist">
				<view class="left">
					<text>用户姓名</text>
				</view>
				<view class="right">
					<input type="text" maxlength="8" placeholder="请输入用户姓名" v-model="user_name"
						placeholder-class="inputColor" :disabled="!btnConf.allow_sub">
				</view>
			</view>
			<view class="inputlist">
				<view class="left">
					<text>手机号</text>
				</view>
				<view class="right">
					<input type="number" placeholder="请输入手机号" v-model="tel_no" maxlength="11"
						placeholder-class="inputColor" :disabled="!btnConf.allow_sub">
				</view>
			</view>
			<view class="inputlist">
				<view class="left">
					<text>证件类型</text>
				</view>
				<view class="right" v-if="!btnConf.allow_sub">
					<input type="text" placeholder="" :value="auth_name" placeholder-class="inputColor" disabled>
				</view>
				<view class="right" v-else>
					<picker mode="selector" :range="auth" @change="choose_auth" :value="value">
						<view>{{auth_name}}</view>
					</picker>
				</view>
			</view>
			<view class="inputlist">
				<view class="left">
					<text>证件号码</text>
				</view>
				<view class="right">
					<input type="text" placeholder="请输入证件号码" maxlength="18" v-model="cert_id"
						placeholder-class="inputColor" :disabled="!btnConf.allow_sub">
				</view>
			</view>
			<view class="btn" v-if="btnConf.allow_sub">
				<button class="btn_sumbit" @click="authsub" :loading="loading"
					:disabled="loading">{{btnConf.text}}</button>
			</view>
			<view class="btn" v-else>
				<button class="btn_sumbit" :disabled="loading">{{btnConf.text}}</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		UserAuth,
		UserAuthSub
	} from "@/api/fast.js"
	export default {
		data() {
			return {
				auth: [],
				auth_ids: [],
				auth_name: '请选择',
				user_name: '',
				tel_no: '',
				cert_type: '',
				cert_id: '',
				value: 0,
				is_auth: false,
				loading: false,
				cert_conf: '',
				btnConf: [],
				info: ''
			}
		},
		onLoad() {
			this.UserAuth()
		},
		onShow() {

		},
		methods: {
			UserAuth() {
				UserAuth().then(res => {
					let info = res.data.info
					this.btnConf = res.data.btnConf
					this.cert_conf = res.data.cert_type
					this.auth = Object.values(this.cert_conf)
					this.auth_ids = Object.keys(this.cert_conf)
					if (info) {
						this.user_name = info.user_name
						this.tel_no = info.tel_no
						this.auth_name = info.auth_name
						this.cert_type = info.cert_type
						this.cert_id = info.cert_id
					}
				})
			},
			choose_auth(e) {
				this.auth_name = this.auth[e.detail.value]
				this.cert_type = this.auth_ids[e.detail.value]
			},
			authsub() {
				if (this.loading) {
					return false
				}
				if (this.user_name == '' || this.tel_no == '' || this.cert_type == '' || this.cert_id == '') {
					uni.showToast({
						title: '请填写完整信息',
						icon: 'none'
					})
					return false
				}
				this.loading = true
				UserAuthSub({
					user_name: this.user_name,
					tel_no: this.tel_no,
					cert_type: this.cert_type,
					cert_id: this.cert_id,
				}).then(res => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					if (res.status == 1) {
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/tabBar/user/user'
							})
						}, 800)
					} else {
						this.loading = false
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #0F172A;
		padding: 10px 0;
	}

	.passwordbox {
		position: fixed;
		width: 100%;
		left: 0;
		height: 100vh;
		background: #0000003b;
		top: 0;
		z-index: 9;

		.passwordmain {
			position: fixed;
			z-index: 999;
			background: #fff;
			width: 94%;
			left: 3%;
			padding: 40px 10px;
			box-sizing: border-box;
			border-radius: 8px;
			top: 25%;

			.password_title {
				font-size: 14px;
				font-weight: bold;
				border-bottom: 1px solid #ccc;
				padding-bottom: 8px;
			}

			input {
				margin-top: 10px;
				font-size: 14px;
				padding: 10px;
			}

			.btns {
				display: flex;
				justify-content: space-around;
				margin-top: 15px;

				.cancel {
					width: 40%;
					text-align: center;
					height: 40px;
					line-height: 40px;
					color: skyblue;
					border: 1px solid skyblue;
					border-radius: 8px;
				}

				.sure {
					width: 40%;
					text-align: center;
					height: 40px;
					line-height: 40px;
					border: 1px solid skyblue;
					background-color: skyblue;
					border-radius: 8px;
					color: #fff;
				}
			}
		}


	}

	.tips {
		font-size: 14px;
		margin-top: 10px;
		padding: 0 20px;
		color: #777;
	}

	.title {
		text-align: right;
		padding: 10px;
		color: #EB655D;
		font-size: 14px;
	}

	.typebox {
		padding: 10px;

		.type_item {
			display: flex;
			align-items: center;
			padding: 5px 0;
			font-size: 14px;

			text {
				margin-right: 20px;
			}

			radio-group {
				display: flex;
			}

			label {
				display: flex;
				align-items: center;
			}
		}
	}

	.btn {
		margin-top: 15px;

		.btn_sumbit {
			background: #798AD6;
			color: #fff;
			width: 80%;
			font-size: 14px;
			box-sizing: border-box;
		}
	}

	.business {
		background: #1E293B;
		width: 96%;
		margin: 0 auto;
		border-radius: 10px;
		color: #fff;
		padding-bottom: 10px;
	}

	.inputlist {
		display: flex;
		font-size: 14px;
		padding: 18px 10px;
		border-bottom: 1px solid #303C4F;

		.left {
			width: 25%;
			display: flex;

			.hx {
				display: block;
				width: 5px;
				color: red;
				margin-right: 3px;
			}
		}

		.right {
			width: 70%;

			input {
				font-size: 14px;
			}

			.picker_text {
				color: #fff;
			}

			.inputColor {
				color: #fff;
			}


		}
	}
</style>